
package msu.ml.gis;

public class DBFAttributeHeader
{
   private byte [] name;
   private char type;
   private int length;
   private IDBFAttributeConverter converter;

   private static IDBFAttributeConverterFactory factory = 
      new DefaultAttributeConverterFactory();

   public DBFAttributeHeader(String name, char type, int length)
   {
      setName(name);
      this.type = type;
      this.length = length;

      converter = factory.createConverter(type, length);
   }

   public byte [] getName()
   {
      return this.name;
   }

   public char getType()
   {
      return this.type;
   }

   public int getLength()
   {
      return this.length;
   }

   public byte [] convertValue(Object obj)
   {
      return converter.convertValue(obj);
   }

   public void setName(String name)
   {
      try
      {
         String result = name.toUpperCase();
         result = result.replace(' ','_');
         if(result.length() > 11)
            result = result.substring(0, 10);
         this.name = result.getBytes("UTF-8");
      }
      catch(java.io.UnsupportedEncodingException e)
      {
         System.out.println("Unsupported Encoding");
      }
   }

   public void setType(char type)
   {
      this.type = type;
   }

   public void setLength(int length)
   {
      this.length = length;
   }
}
